﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Master.Master" AutoEventWireup="true"
    CodeBehind="Write_AdminSend.aspx.cs" Inherits="MsgCenter.Web.Pages.Write.Write_AdminSend" %>

<asp:Content ID="Content1" ContentPlaceHolderID="headerContent" runat="server">
    <style>
        .error
        {
            color: red;
        }
    </style>
    <link rel="stylesheet" href="../../JavaScript/FirePlat/assets/css/chosen.css" />
    <link href="../../JavaScript/FirePlat/assets/css/bootstrap-timepicker.css" rel="stylesheet"
        type="text/css" />
    <link href="../../JavaScript/FirePlat/assets/js/tagsinput/jquery.tagsinput.css" rel="stylesheet"
        type="text/css" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="mainContent" runat="server">
    <div class="page-content">
        <div class="page-header">
            <h1>
                管理员批量发送
            </h1>
        </div>
        <div class="row">
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->
                <form id="myform" class="form-horizontal">
                <div class="form-group">
                    <label class="col-sm-3 control-label no-padding-right" for="form-field-1">
                        发送类型
                    </label>
                    <div class="col-sm-5">
                        <%=strSelect.ToString() %>
                    </div>
                </div>
                <div class="space-4">
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label no-padding-right" for="form-field-1">
                        接受人
                    </label>
                    <div class="col-sm-9">
                        <input id="txtRecevieUser" type="text" class="tags required" />
                        <span class="input-group-btn">
                            <button class="btn btn-xs btn-warning" type="button" onclick="showSelectUser();">
                                <i class="icon-fire bigger-110"></i>选择
                            </button>
                        </span>
                        <input type="hidden" id="txtRecevieLoginUser" />
                    </div>
                </div>
                <div class="space-4">
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label no-padding-right" for="txtSendContent">
                        发送内容
                    </label>
                    <div class="col-sm-9">
                        <textarea class="form-control limited required" id="txtSendContent" maxlength="100"></textarea>
                    </div>
                </div>
                <div class="space-4">
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label no-padding-right" for="form-field-2">
                        是否即时发送
                    </label>
                    <div class="col-sm-9">
                        <input name="chkIsAutoSend" id="chkIsAutoSend" class="ace ace-switch ace-switch-5"
                            type="checkbox" checked="checked" />
                        <span class="lbl"></span>
                    </div>
                </div>
                <div id="divSelectDate">
                    <div class="space-4">
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for="form-field-2">
                            发送日期
                        </label>
                        <div class="col-sm-2">
                            <div class="input-group">
                                <input class="form-control date-picker" id="txtSendDate" type="text" data-date-format="yyyy-mm-dd" />
                            </div>
                        </div>
                    </div>
                    <div class="space-4">
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for="form-field-2">
                            发送时间
                        </label>
                        <div class="col-sm-2">
                            <div class="input-group bootstrap-timepicker">
                                <div class="bootstrap-timepicker-widget dropdown-menu">
                                    <table>
                                        <tbody>
                                            <tr>
                                                <td>
                                                    <a href="#" data-action="incrementHour"><i class="icon-chevron-up"></i></a>
                                                </td>
                                                <td class="separator">
                                                    &nbsp;
                                                </td>
                                                <td>
                                                    <a href="#" data-action="incrementMinute"><i class="icon-chevron-up"></i></a>
                                                </td>
                                                <td class="separator">
                                                    &nbsp;
                                                </td>
                                                <td>
                                                    <a href="#" data-action="incrementSecond"><i class="icon-chevron-up"></i></a>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <input type="text" name="hour" class="bootstrap-timepicker-hour" maxlength="2">
                                                </td>
                                                <td class="separator">
                                                    :
                                                </td>
                                                <td>
                                                    <input type="text" name="minute" class="bootstrap-timepicker-minute" maxlength="2">
                                                </td>
                                                <td class="separator">
                                                    :
                                                </td>
                                                <td>
                                                    <input type="text" name="second" class="bootstrap-timepicker-second" maxlength="2">
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <a href="#" data-action="decrementHour"><i class="icon-chevron-down"></i></a>
                                                </td>
                                                <td class="separator">
                                                </td>
                                                <td>
                                                    <a href="#" data-action="decrementMinute"><i class="icon-chevron-down"></i></a>
                                                </td>
                                                <td class="separator">
                                                    &nbsp;
                                                </td>
                                                <td>
                                                    <a href="#" data-action="decrementSecond"><i class="icon-chevron-down"></i></a>
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                                <input id="timepicker1" type="text" class="form-control">
                                <span class="input-group-addon"><i class="icon-time bigger-110"></i></span>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="space-4">
                </div>
                <div class="clearfix form-actions">
                    <div class="col-md-offset-3 col-md-9">
                        <button class="btn btn-info" type="button" id="btnSave">
                            <i class="icon-ok bigger-110"></i>发送
                        </button>
                        &nbsp; &nbsp; &nbsp;
                        <button class="btn" type="button" id="btnReset">
                            <i class="icon-undo bigger-110"></i>重填
                        </button>
                    </div>
                </div>
                </form>
            </div>
        </div>
    </div>
    <script src="../../JavaScript/FirePlat/assets/js/chosen.jquery.min.js"></script>
    <script src="../../JavaScript/FirePlat/assets/js/jquery.inputlimiter.1.3.1.min.js"
        type="text/javascript"></script>
    <script type="text/javascript" src="../../JavaScript/FirePlat/assets/js/date-time/bootstrap-timepicker.min.js"></script>
    <script src="../../JavaScript/FirePlat/assets/js/jquery.validate.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="<%=ResolveClientUrl("~/JavaScript/FirePlat/assets/js/jqGrid/myJqgrid.js") %>"></script>
    <script src="../../JavaScript/FirePlat/assets/js/tagsinput/jquery.tagsinput.js" type="text/javascript"></script>
    <script type="text/javascript">
        jQuery(function ($) {
            $('#txtSendContent').inputlimiter({ remText: '你还能输入 %n 个字', limitText: '最长允许 : %n.' });
            $(".date-picker").datepicker({
                language: "zh-CN",
                autoclose: true, //选中之后自动隐藏日期选择框
                clearBtn: true, //清除按钮
                todayBtn: true, //今日按钮
                format: "yyyy-mm-dd"
            }).next().on(ace.click_event, function () {
                $(this).prev().focus();
            });

            $('#timepicker1').timepicker({
                minuteStep: 1,
                showSeconds: true,
                showMeridian: false
            }).next().on(ace.click_event, function () {
                $(this).prev().focus();
            });

            $(".chosen-select").chosen();


            $("#btnSave").bind("click", function () {
                PostData();
                return false;
            });

            $("#btnReset").bind("click", function () {
                window.location = 'Write_MySend.aspx?ModuleID=<%=strRequestID %>';
                return false;
            });
            $("#chkIsAutoSend").bind("click", function () {
                if ($("#chkIsAutoSend").attr('checked') == undefined) {
                    $("#chkIsAutoSend").attr("checked", true); //打勾
                    $("#divSelectDate").hide();
                }
                else {
                    $("#chkIsAutoSend").attr("checked", false); //不打勾  
                    $("#divSelectDate").show();
                }
            });
            $("#divSelectDate").hide();

            $("#myform").validate();

            $('#txtRecevieUser').tagsInput({ width: '500px', interactive: false, onRemoveTag: onRemoveTag });
        });

        function onRemoveTag(tag) {
            var selectUser = $("#txtRecevieLoginUser").val();
            var spsz = selectUser.split(',');
            var select = "";
            for (var len = 0; len < spsz.length; len++) {
                var u = spsz[len].split('&');
                if (u[0] != tag) {
                    if (select == "") {
                        select = u[0] + "&" + u[1];
                    }
                    else {
                        select = select + "," + u[0] + "&" + u[1];
                    }
                }
            }
            $("#txtRecevieLoginUser").val(select);
        }

        function showSelectUser() {
            var o = {
                closeButton: true,
                title: "选择用户",
                href: "../User/SelectUser.aspx",
                innerHeight: "500px", //默认高度
                innerWidth: "1000px" //默认宽度
            };
            showColorbox(o);
        }

        function SetSelectUser(varUserName, varUserLoginName) {
            $("#txtRecevieUser").importTags(varUserName);
            $("#txtRecevieLoginUser").val(varUserLoginName);
        }

        function CBClose() {
            $.colorbox.close();
        }

        function PostData() {
            var sendType = $("#sltSendType").val();
            if (sendType == "" || sendType == null) {
                showDialogMessage("请先选择发送类型!");
                return false;
            }
            var receviceUserID = $("#txtRecevieLoginUser").val();
            if (receviceUserID == "") {
                showDialogMessage("请先选择接受人员!");
                return false;
            }
            var receviceUserIDS = receviceUserID.split(',');
            receviceUserID = "";
            for (var len = 0; len < receviceUserIDS.length; len++) {
                var u = receviceUserIDS[len].split('&');
                if (receviceUserID == "") {
                    receviceUserID = u[1];
                }
                else {
                    receviceUserID = receviceUserID + "," + u[1];
                }
            }
            var sendContent = $("#txtSendContent").val();
            if (sendContent == "") {
                showDialogMessage("请先输入发送内容!");
                return false;
            }
            var IsAutoSend = $("#chkIsAutoSend").attr('checked');
            if (IsAutoSend == undefined) {
                IsAutoSend = "0";
            }
            else {
                IsAutoSend = "1";
            }
            var sendDate = "";
            var sendTime = "";
            if (IsAutoSend == "0") {
                sendDate = $("#txtSendDate").val();
                if (sendDate == "") {
                    showDialogMessage("请先选择发送日期!");
                    return false;
                }
                sendTime = $("#timepicker1").val();
                if (sendTime == "") {
                    showDialogMessage("请先选择发送时间!");
                    return false;
                }
            }
            $.ajax({
                type: 'POST',
                url: "../../Handlers/Handler_Write.ashx?method=Write_MySend",
                data: { UserID: receviceUserID, sendContent: sendContent, sendType: sendType.toString(), sendDate: sendDate, sendTime: sendTime, IsAutoSend: IsAutoSend, random: Math.random() },
                success: function (msg) {
                    var jsonData = jQuery.parseJSON(msg);
                    if (jsonData.State == "true") {
                        var o = {
                            Message: "发送数据成功！",
                            OnClick: function () { window.location = 'Write_MySend.aspx?ModuleID=<%=strRequestID %>'; }
                        };
                        showDialog(o);
                    }
                    else {
                        alert("发送失败：" + jsonData.Message);
                    }

                },
                error: function (msg) {
                    alert("发送失败：请求服务路径出现异常，请通知管理员检查");
                }
            });
            return false;
        }

    </script>
</asp:Content>
